import json
import os

import sumolib

import rou.constants as rc
from utils import common_util
from utils.emergencyLane_util import get_emergencyLaneConfig_info, get_emergencyLaneControl_info

def get_station_info():
    station_path = rc.DEFAULT_SCENE_STATIONCONFIG_PATH
    station_path_name = os.path.join(station_path, rc.DEFAULT_STATIONCONFIG_NAME)
    with open(station_path_name, "r", encoding="utf-8") as f:
        data = f.read()
    return json.loads(data)
def get_station_number(lon,lat):
    min_distance = float('inf')
    station_infos=get_station_info()
    for station_info_key,station_info_value in station_infos.items():
        distance=common_util.calculate_distance(lon,lat,station_info_value['lon'],station_info_value['lat'])
        if distance < min_distance:
            min_distance = distance
            station_info_id= station_info_key
    return min_distance,station_info_id
def get_edge(edge_id1,edge_id2,traci):
    # 获取路段列表
    links = traci.simulation.getLinks()


    # 遍历路段列表
    for link in links:
        from_node = traci.edge.getFromNode(link[0])
        to_node = traci.edge.getToNode(link[0])

        if link[0] == edge_id1 and from_node < to_node:
            print(f"{edge_id1}在{edge_id2}前面")
        elif link[0] == edge_id1 and from_node > to_node:
            print(f"{edge_id1}在{edge_id2}后面")

        if link[0] == edge_id2 and from_node < to_node:
            print(f"{edge_id2}在{edge_id1}后面")
        elif link[0] == edge_id2 and from_node > to_node:
            print(f"{edge_id2}在{edge_id1}前面")
if __name__ == "__main__":
    # get_station_number(108.895349,34.373273)
    aa=get_emergencyLaneConfig_info()
    print(aa)
    aaa=dict()
    aaa.items()

